<include file="Common:header" />
<TYimport plugin='datepicker' />
<TYjs file='fix_table_title'/>
<!-- <TYjs file='init'/> -->

<style>
.success{width:20%;float:left;}
.success img{width:100%}
</style>

<div class="table_content">
    <form action="{:U(MODULE_NAME.'/'.CONTROLLER_NAME.'/'.ACTION_NAME)}" method="post" class="ajax_form">
        <div class="toolbar">
            <select id="select_province" name="search_province">
                <option value="">--请选择--</option>
                <foreach name="province" item="so" >
                    <option value="{$so.provinceid}">{$so.provincename}</option>
                </foreach>
            </select>
            <select id="select_city" name="search_city">
                <option value="">--请选择--</option>
            </select>
            <!-- 请填订单号 -->
            <input type="text" class="text w150" name="keywords"  title="请填医院名称" placeholder="请填医院名称"/>
            <!-- 查询 -->
            <button type="submit">查询</button>
        </div>
    </form>
    <a class="a_btn add_server_name" style="margin-bottom:10px;cursor:pointer;">添加医院</a>
        <table class="orders_table">
            <tr>
                <th style="min-width:100px;">所属城市</th>
                <th style="min-width:100px;">医院名称</th>
                <th style="min-width:100px;">收费金额</th>
                <th style="min-width:100px;">創建時間</th>
                <th style="min-width:100px;">更新時間</th>
                <th style="min-width:100px;">绑定账户</th>
                <th style="min-width:100px;">是否顯示</th>
                <th width="130px">操作</th>
            </tr>
            <foreach name='list' item='vo'>
                <tr>
                	<td class="txtc">{$vo.province_name} {$vo.city_name} {$vo.district_name}</td>
                	<td class="txtc">
                        {$vo.hospital_name}
                	</td>
                	<td class="txtc">￥{$vo.hospital_price}</td>
                	<td class="txtc">{$vo.create_time|date="Y-m-d H:i",###}</td>
                    <td class="txtc">{$vo.update_time|date="Y-m-d H:i",###}</td>
                    <td class="txtc">
                        <empty name="vo.user_name">
                            <p style="color: red;margin:5px 0;">待绑定</p>
                            <a class="a_btn add_nurse_account" hospital_id="{$vo['id']}"style="margin:0 0 5px 0;cursor:pointer;">添加账户</a>
                            <!-- <button class="startMake" hospital_id="{$vo['id']}">绑定账户</button> -->
                        <else/>
                            {$vo.user_name}
                        </empty>
                    </td>
                    <td class="txtc">
                        <input type="button" class="js_status status_{$vo['status']?'enable':'disable'}" url="{:U(MODULE_NAME.'/Audit/change_hospital_status',array('id'=>$vo['id']))}"/>
                    </td>
                    <td class="txtc">
                        <a class="delete" href="{:U(MODULE_NAME.'/Audit/delete_hospital',array('id'=>$vo['id']))}" title="删除"></a>
                    </td>
                </tr>
                <tr style="height:10px;" >
                    <td class="bgcf5"colspan="8"></td>
                </tr>
            </foreach>
        </table>
    <div class="page">{$page}</div>
</div>

<!-- 添加医院--服务 -->
<div id="add_name" style="display:none;">
    <form action="{:U(GROUP_NAME.'/'.MODULE_NAME.'/change_delivery')}" method="post" id="upForm">
        <table class="edit_table">
        	<tr>
                <td class="tablehead">所在省份</td>
                <td>
                    <select type="text" name="province_id" class="w250 selectProvince" >
                        <option value="">--请选择--</option>
                        <foreach name="province" item="so" >
                            <option value="{$so.provinceid}">{$so.provincename}</option>
                        </foreach>
                    </select>
                </td>
            </tr>
			<tr>
				<td class="tablehead">所在城市</td>
				<td>
                    <select type="text" name="city_id" class="w250 selectCity" >
                        <option value="">--请选择--</option>
                    </select>
				</td>
			</tr>
			<tr>
				<td class="tablehead">所在区（县、镇）</td>
				<td>
                    <select type="text" name="district_id" class="w250 selectDistrict" >
                        <option value="">--请选择--</option>
                    </select>
				</td>
			</tr>
            <tr>
                <td class="tablehead">医院名称</td>
                <td><input type="text" name="hospital_name" class="w250"/></td>
            </tr>
            <tr>
                <td class="tablehead">预约订单金额</td>
                <td><input type="text" name="hospital_price" class="w250"/></td>
            </tr>
            <tr>
                <td class="tablehead"></td>
                <td><input type="button" name="confirm_server_name" value="添加" style="padding:6px 20px;"/></td>
            </tr>
        </table>
    </form>
</div>

<div id="add_account" style="display:none;">
        <table class="edit_table">
            <tr>
                <td class="tablehead">用户名</td>
                <td><input type="text" name="user_name" class="w250"/></td>
            </tr>
            <tr>
                <td class="tablehead">密码</td>
                <td><input type="password" name="password" class="w250"/></td>
            </tr>
            <tr>
                <td class="tablehead">确认密码</td>
                <td><input type="password" name="repet_password" class="w250"/></td>
            </tr>
            <tr>
                <td class="tablehead"></td>
                <td><input type="button" name="confirm_nurse_account" value="添加" style="padding:6px 20px;"/></td>
            </tr>
        </table>
</div>

<script type="text/javascript">
    $(function() {
        //添加月卡
    	$('.add_server_name').click(function(){
    		art.dialog({
    			title:'添加医院',
     			content: document.getElementById('add_name'),
    		});
    	});

        //添加账户
        $('.add_nurse_account').click(function(){
            art.dialog({
                title:'添加账户',
                content: document.getElementById('add_account'),
            });
        });

        //选择省份触发市区--添加
        $(".selectProvince").on('change', function() {
            var savePostData = {};
            savePostData.proVal = $(".selectProvince").val();
            $.post("{:U(MODULE_NAME.'/Audit/getCityByProvince')}",savePostData,function(data){
                var cityHtml = "<option value=\"\">--请选择--</option>";
                $.each(data.data,function(index, el) {
                    cityHtml += "<option value=\""+el.cityid+"\">"+el.cityname+"</option>";
                });
                $(".selectCity").html(cityHtml);
            });
        });

        //选择省份触发市区--添加
        $(".selectCity").on('change', function() {
            var savePostData = {};
            savePostData.cityVal = $(this).val();
            $.post("{:U(MODULE_NAME.'/Audit/getDistrictByCity')}",savePostData,function(data){
                var districtHtml = "<option value=\"\">--请选择--</option>";
                $.each(data.data,function(index, el) {
                	districtHtml += "<option value=\""+el.districtid+"\">"+el.districtname+"</option>";
                });
                $(".selectDistrict").html(districtHtml);
            });
        });

        //绑定唯一账户
        $('input[name=confirm_nurse_account]').click(function(){
            var url = "{:U(MODULE_NAME.'/'.CONTROLLER_NAME.'/bindingAccount')}";
            var postdata = {
                hospital_id : $('.add_nurse_account').attr('hospital_id'),
                user_name   : $('input[name=user_name]').val(),
                password    : $('input[name=password]').val()
            }
            if ( $('.add_nurse_account').attr('hospital_id')=='' ) {
                callBackTips(0,'请刷新页面,再试!');
                return false;
            }else if( $('input[name=user_name]').val()=='' ){ /*備註必填*/
                callBackTips(0,'请填写用户名');
                return false;
            }else if( $('input[name=password]').val()=='' ){ /*備註必填*/
                callBackTips(0,'请填写密码');
                return false;
            }else if( $('input[name=password]').val() != $('input[name=repet_password]').val() ){ /*備註必填*/
                callBackTips(0,'密码不一致,请重新填写!');
                return false;
            }
            $.ajax({
                url: url,
                type: "post",
                dataType: "JSON",
                data:postdata,
                async: "true",
                success: function (data) {
                    if (data.status == 1){
                        callBackTips(data.status, data.info,data.url);
                    }else{
                        callBackTips(data.status, data.info,data.url);
                    }
                }
            });
        });

        //提交添加医院
    	$('input[name=confirm_server_name]').click(function(){
            var saveData = {};
			saveData.province_id     = $('select[name=province_id]').val();
			saveData.city_id         = $('select[name=city_id]').val();
			saveData.district_id     = $('select[name=district_id]').val();
			saveData.hospital_name   = $('input[name=hospital_name]').val();
			saveData.hospital_price  = $('input[name=hospital_price]').val();
            if ( $('select[name=province_id]').val()=='' ) {
                callBackTips(0,'请选择省份');
                return false;
            }else if( $('select[name=city_id]').val()=='' ){ /*備註必填*/
                callBackTips(0,'请选择城市');
                return false;
            }else if( $('select[name=district_id]').val()=='' ){ /*備註必填*/
                callBackTips(0,'请选择县区镇');
                return false;
            }else if( $('input[name=hospital_name]').val()=='' ){ /*備註必填*/
                callBackTips(0,'请填写医院名字');
                return false;
            }else if( $('input[name=hospital_price]').val()=='' ){ /*備註必填*/
                callBackTips(0,'请填写医院价格');
                return false;
            }
    		$.ajax({
                url: "{:U(MODULE_NAME.'/'.CONTROLLER_NAME.'/add_hospital')}" ,
                type: 'POST',
    	        data : saveData,
    	        async: false,
    			dataType: 'json',
                success: function (returndata) {
               		if(returndata.status){
               		    callBackTips(returndata.status,returndata.info,returndata.url);
            		}else{
            			callBackTips(0,returndata.info);
            		}
                },
           });
    	});
    });
</script>
<include file="Common:footer" />
